package wangwenjun.phase1.close;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @author ChangLiang
 * @date 2020/5/29
 */
public class InterruptThreadExitV2 {

    private static Logger logger = LoggerFactory.getLogger(InterruptThreadExitV2.class);

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread() {
            @Override
            public void run() {
                logger.info("I will start work");
                for (; ; ) {
                    //working.
                    try {
                        TimeUnit.MILLISECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                logger.info("I will be exiting.");
            }
        };
        t.start();
        TimeUnit.SECONDS.sleep(5);
        logger.info("System will be shutdown.");
        t.interrupt();
    }
}
